use std::fs::File;
use std::io::Read;

fn main() -> Result<(), String> {
    // 第一阶段：氧气系统检测
    let o2_status = check_oxygen_system(80)?;
    println!("{}", o2_status);

    // 第二阶段：读取舱压数据
    let pressure = read_pressure_data("pressure.txt")?;
    println!("当前舱压：{}千帕", pressure);

    // 第三阶段：终极安全检查
    verify_emergency_exits(); // 可能触发panic

    Ok(())
}

fn check_oxygen_system(level: u32) -> Result<String, String> {
    match level {
        0..=20 => Err("☠️ 氧气严重不足！".into()),
        21..=50 => Ok("⚠️ 氧气量偏低，建议补充".into()),
        _ => Ok("✅ 氧气系统正常".into())
    }
}

fn read_pressure_data(path: &str) -> Result<f32, String> {
    let mut file = File::open(path)
        .map_err(|e| format!("🛸 无法读取压力文件：{}", e))?;

    let mut content = String::new();
    file.read_to_string(&mut content)
        .map_err(|e| format!("📉 数据解析失败：{}", e))?;

    content.trim().parse()
        .map_err(|_| "🔢 舱压数据格式异常".into())
}

fn verify_emergency_exits() {
    let exits_functional = false;
    assert!(exits_functional, "🚨 紧急出口验证失败！");
}
